package com.bohua.intermediary.controller;

import com.bohua.intermediary.common.Lay;
import com.bohua.intermediary.common.Msg;
import com.bohua.intermediary.entity.SysDept;
import com.bohua.intermediary.entity.SysRole;
import com.bohua.intermediary.security.MyUser;
import com.bohua.intermediary.service.SysRoleService;
import com.bohua.intermediary.utils.SecurityUtils;
import com.bohua.intermediary.vo.InputTreeVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 * @author qian
 * @email 1415261159@qq.com
 * @date 2019/01/19
 */
@Controller
@RequestMapping("/sysRole")
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;

    @RequestMapping
    public String sysRole(){
        return "sysRole/sysRole";
    }
    @RequestMapping("/add")
    public String add(){
        return "sysRole/addSysRole";
    }

    @RequestMapping("/update")
    public String update(){
        return "sysRole/updateSysRole";
    }

    @RequestMapping("/getSysRoles")
    @ResponseBody
    public Lay getSysRoles(SysRole sysRole,Integer page,Integer limit){
        return sysRoleService.getSysRoles(sysRole,page,limit);
    }
    @RequestMapping("/addSysRole")
    @ResponseBody
    public Msg addSysRole(SysRole sysRole){
        MyUser user= SecurityUtils.getUser();
        sysRole.setOperName(user.getMeUser().getName());
        return sysRoleService.addSysRole(sysRole);
    }

    @RequestMapping("/updateSysRole")
    @ResponseBody
    public Msg updateSysRole(SysRole sysRole){
        return sysRoleService.updateSysRole(sysRole);
    }

    @RequestMapping("/delSysRole")
    @ResponseBody
    public Msg delSysRole(SysRole sysRole){
        return sysRoleService.delSysRole(sysRole);
    }

    @RequestMapping("/getTree")
    @ResponseBody
    public List<InputTreeVo> getTree(SysRole sysRole){
        return sysRoleService.getList(sysRole);
    }
}
